//
//  FirstViewController.m
//  轮胎商城
//
//  Created by 张晋磊 on 2017/3/21.
//  Copyright © 2017年 张晋磊. All rights reserved.
//

#import "FirstViewController.h"
#import "FirstScroll.h"
#import "FirstTableCell.h"
#import "FirstTwoTableCell.h"
#import "TableImgCell.h"
#import "TableScrollCell.h"

@interface FirstViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) NSMutableArray *arrData;

@property (nonatomic,retain) UITableView *table;
@property (nonatomic,retain) FirstScroll *firScro;

@end

@implementation FirstViewController

-(NSMutableArray *)arrData{

    if(!_arrData){
    
        _arrData = [NSMutableArray array];
    }
    return _arrData;
}

-(UITableView *)table{

    if(!_table){
    
        CGSize size = self.view.frame.size;
        _table = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, size.width, size.height-self.tabBarController.tabBar.frame.size.height-64) style:UITableViewStylePlain];
        
        _table.dataSource = self;
        _table.delegate   = self;
        
        NSArray *arr = @[@"z2.png",@"z6.png",@"z7.png",@"z2.png",@"z6.png"];
        _firScro = [[FirstScroll alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
        
        _firScro.arrImg = arr;
        
        [self.view addSubview:_firScro];
        
        self.automaticallyAdjustsScrollViewInsets = NO;
        
        _table.tableHeaderView = _firScro;
        
    }
    return _table;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.table];
    
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 9;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if(indexPath.row == 0){
    
        return 45;
    }else if (indexPath.row == 1){
    
        return 182;
    }
    return 120;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    if(indexPath.row == 0){
    
        FirstTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bb"];
        
        if(!cell){
        
            cell = [[FirstTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"bb"];
        }
        
        [cell clickBtBlock:^(NSInteger tag) {
            if(tag == 100){
            
                return @"11";
            }else if (tag == 101){
            
                return @"22";
            }else if (tag == 102){
            
                return @"33";
            }else if (tag == 103){
            
                return @"44";
            }
            return @"aa";
        }];
        
        return cell;
    }else if (indexPath.row == 1){
    
        FirstTwoTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cc"];
        
        if(!cell){
        
            cell = [[FirstTwoTableCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cc"];
        }
        [cell computeBlockGetUrl:^NSString *(NSString *str) {
            if([str isEqualToString:@"矿山车胎"]){
            
                return @"矿山";
            }else if ([str isEqualToString:@"自行车胎"]){
            
                return @"自行车";
            }else if ([str isEqualToString:@"摩托车胎"]){
            
                return @"摩托车";
            }else if ([str isEqualToString:@"工业车胎"]){
            
                return @"工业";
            }
            return @"";
        }];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }else if (indexPath.row == 3){
    
        TableScrollCell *cell = [tableView dequeueReusableCellWithIdentifier:@"dd"];
        
        if(!cell){
        
            cell = [[TableScrollCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"dd"];
        }
        
        NSArray *arrimg = @[@"z2.png",@"z6.png",@"z7.png",@"z2.png"];
        cell.arr = arrimg;
        
        [cell coputeButtonClick:^NSString *(NSInteger index) {
         
            switch (index) {
                case 100:
                    return @"按钮1";
                    break;
                case 101:
                    return @"按钮2";
                    break;
                case 102:
                    return @"按钮3";
                    break;
                case 103:
                    return @"按钮4";
                    break;
                    
                default:
                    break;
            }
            return @"";
        }];
        
        
        return cell;
    }
    else{
    
        TableImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"aa"];
        
        if(!cell){
            
            cell = [[TableImgCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"aa"];
        }
        
        
        cell.img.image = [UIImage imageNamed:@"scroll04"];
        return cell;
    }
    
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
